package com.bzgwl.cloud_gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @author Professor_Kong
 * @version 1.0
 * @date 2020/2/28 10:27
 */

@Configuration
public class TokenConfig {

    private  String SiGN_KEY="sing_key";

    //令牌存储策略
    @Bean
    public TokenStore tokenStore(){
        //1.内存模式
//        return new InMemoryTokenStore();
        //2. JWT token 替代令牌策略
        return new JwtTokenStore(accessTokenConverter());
    }


    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter tokenConverter = new JwtAccessTokenConverter();

        tokenConverter.setSigningKey(SiGN_KEY);
        return tokenConverter;
    }
}
